package com.ucar.train.service.impl;

import com.ucar.train.dao.CarMapper;
import com.ucar.train.dao.StoreCarMappingMapper;
import com.ucar.train.dto.CarDTO;
import com.ucar.train.dto.StoreCarMappingDTO;
import com.ucar.train.service.CarService;
import com.ucar.train.vo.CarVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sun.rmi.runtime.Log;

import java.util.List;

@Service
public class CarServiceImp implements CarService {
    @Autowired
    private CarMapper carMapper;
    @Autowired
    private StoreCarMappingMapper storeCarMappingMapper;


    @Override
    public List<CarDTO> selectCarByStoreId(String storeId) {
        return carMapper.selectCarByStoreId(storeId);
    }

    /**
    * @Description 
    * @author Lenny
    * @param  
    * @createDate 2019/8/15 
    **/
    @Override
    public Integer updateCarOfStoreIdAfterSchedul(List<String> carIdList, String storeId) {
        return carMapper.updateCarOfStoreIdAfterSchedul(carIdList,storeId);
    }

    @Override
    public StoreCarMappingDTO selectByCarId(String  carId){
        return storeCarMappingMapper.selectByCarId(carId);
    }

    @Override
    public int updateByPrimaryKeySelective(StoreCarMappingDTO record){
        return storeCarMappingMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public CarDTO selectCarDTOByCarId(String carID) {
        return carMapper.selectCarDTOByCarId(carID);
    }

    @Override
    public  int updateByCarId( CarVO carVO){
        //todo  CarVO to CarDTO
        CarDTO carDTO=new CarDTO();
        carDTO.setId(carVO.getId());
        carDTO.setCarId(carVO.getCarId());
        carDTO.setCarNum(carVO.getCarNum());
        carDTO.setMaintenanceTime(carVO.getMaintenanceTime());
        carDTO.setType(carVO.getType());
        carDTO.setState(carVO.getState());
        return  carMapper.updateByCarId(carDTO);
    }

    @Override
    public int updateScheduleCar(String carId,String  storeId){
        StoreCarMappingDTO storeCarMappingDTO =new StoreCarMappingDTO();
        storeCarMappingDTO.setCarId(carId);
        storeCarMappingDTO.setStoreCode(storeId);
        System.out.println(storeCarMappingDTO.toString());
        return storeCarMappingMapper.updateScheduleCar(storeCarMappingDTO);
    }

    @Override
    public List<CarDTO>selectAllCar(){
        return carMapper.selectAllCar();
    }

}
